import qs from 'qs'
import { INIT_LIST_DATA, VAL_CHANGE, ADD_ITEM, DEL_ITEM } from './action-types'
import axios from 'axios'
const getListData = (data) => ({ type: INIT_LIST_DATA, data: data })
export const valChange = (val) => ({type: VAL_CHANGE, data: val})
export const addItem = (item) => ({type: ADD_ITEM, data: item})
export const delItem = (index) => ({type: DEL_ITEM, data: index})



export const initListData = () => {
  return (dispatch) => {
    axios.post('https://service.hzbanshi.cn/library/search', qs.stringify({
      word: '金',
      currentPage: 1,
      pageSize: 10,
      isClick: 0
    })).then((res) => {
      let result = res.data.data.books.map(obj => obj.title)
      dispatch(getListData(result))
    })
  }
}